package com.buba.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.buba.service.WareDetailsService;
import com.buba.service.WarehousingService;
import common.R;
import entity.sparemanage.WareDetails;
import entity.sparemanage.Warehousing;
import entity.sparemanage.dto.insetWareHouseDto;
import entity.sparemanage.dto.warehouseDto;
import entity.sparemanage.vo.selOneCollectingVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import utils.PageResult;

import java.util.List;

/**
 * <p>
 * 入库记录表 前端控制器
 * </p>
 *
 * @author beisheng
 * @since 2023-05-18
 */
@RestController
@RequestMapping("/warehousing")
public class WarehousingController {
    @Autowired
    private WarehousingService warehousingService;

    @Autowired
    private WareDetailsService wareDetailsService;
    /* *
     * @Author: beisheng
     * @Descriprion: 分页模糊查入库管理列表
     * @Date: 2023/5/25 8:42
     * @Return: common.R
     * @Param: [warehouseDto]
     */

    @PostMapping("/selAllWareHouse")
    public R selAllWareHouse(@RequestBody warehouseDto warehouseDto){
        PageResult pageResult = warehousingService.selAllWareHouse(warehouseDto);
        return R.success(pageResult);
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 新增入库记录
     * @Date: 2023/5/29 10:12
     * @Return: common.R
     * @Param: [insetWareHouseDto]
     */

    @PostMapping("/insetWareHouse")
    public R insetWareHouse(@RequestBody insetWareHouseDto insetWareHouseDto){
        warehousingService.insetWareHouse(insetWareHouseDto);
        return R.success();
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 批量删除入库信息
     * @Date: 2023/5/31 19:58
     * @Return: common.R
     * @Param: [ids]
     */

    @PostMapping("deleteBatch")
    public R deleteBatch(@RequestBody List<Integer> ids){
        for (Integer id : ids) {
            Warehousing warehousing = new Warehousing();
            warehousing.setDeleteFlag(1);
            warehousing.setSpId(id);
            warehousingService.updateById(warehousing);
            wareDetailsService.remove(new QueryWrapper<WareDetails>().eq("use_id",id));
        }
        return R.success();
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 根据入库申请ID查询详细信息
     * @Date: 2023/5/30 14:20
     * @Return: common.R
     * @Param: [spId]
     */

    @GetMapping("/selOneCollecting/{spId}")
    public R selOneCollecting(@PathVariable("spId") Integer spId){
        selOneCollectingVo selOneCollectingVo = warehousingService.selOneCollecting(spId);
        return R.success(selOneCollectingVo);
    }

    /* *
     * @Author: beisheng
     * @Descriprion: 修改入库单信息
     * @Date: 2023/5/30 19:15
     * @Return: common.R
     * @Param: [insetWareHouseDto]
     */

    @PostMapping("/updateCollection")
    public R updateCollection(@RequestBody insetWareHouseDto insetWareHouseDto){
        warehousingService.updateCollection(insetWareHouseDto);
        return R.success();
    }
}


